#include "settings.h"
#include <QSettings>

Settings::Settings(QObject *parent) : QObject(parent)
{

}

QString Settings::getPortName(){
    return QSettings("config.ini", QSettings::IniFormat).value("portName", "").toString();
}

int Settings::getBaudrate(){
    return QSettings("config.ini", QSettings::IniFormat).value("baudrate", 9600).toInt();
}

int Settings::getDatabits(){
    return QSettings("config.ini", QSettings::IniFormat).value("databits", -1).toInt();
}

int Settings::getStopbits(){
    return QSettings("config.ini", QSettings::IniFormat).value("stopbits", -1).toInt();
}

int Settings::getParity(){
    return QSettings("config.ini", QSettings::IniFormat).value("parity", -1).toInt();
}

int Settings::getTheme(){
    return QSettings("config.ini", QSettings::IniFormat).value("theme", 0).toInt();
}

QStringList Settings::getLineColors()
{
    QStringList l = {"#c0504d", "#9bbb59", "#8064a2", "#4bacc6", "#f79646", "#4f81bd"};
    return QSettings("config.ini", QSettings::IniFormat).value("lineColors", l).toStringList();
}

QStringList Settings::getLineNames()
{
    QStringList l;
    for(int i = 0; i != 8; i++)
    {
        l.append(tr("通道 %1").arg(i + 1));
    }
    return QSettings("config.ini", QSettings::IniFormat).value("lineNames", l).toStringList();
}

void Settings::setPortName(QString portName){
    QSettings("config.ini", QSettings::IniFormat).setValue("portName", portName);
}

void Settings::setBaudrate(int baudrate){
    QSettings("config.ini", QSettings::IniFormat).setValue("baudrate", baudrate);
}

void Settings::setDatabits(int index){
    QSettings("config.ini", QSettings::IniFormat).setValue("databits", index);
}

void Settings::setStopbits(int index){
    QSettings("config.ini", QSettings::IniFormat).setValue("stopbits", index);
}

void Settings::setParity(int index){
    QSettings("config.ini", QSettings::IniFormat).setValue("parity", index);
}

void Settings::setTheme(int index){
    QSettings("config.ini", QSettings::IniFormat).setValue("theme", index);
}

void Settings::setLineColors(const QStringList &l)
{
    QSettings("config.ini", QSettings::IniFormat).setValue("lineColors", l);
}

void Settings::setLineNames(const QStringList l)
{
    QSettings("config.ini", QSettings::IniFormat).setValue("lineNames", l);
}
